package com.hjm.project.team.allowanceAward.controller;

import java.text.ParseException;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.team.allowanceAward.domain.AllowanceAward;
import com.hjm.project.team.allowanceAward.service.IAllowanceAwardService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 创业津贴奖励配置Controller
 * 
 * @author maker-platform
 * @date 2021-04-30
 */
@Controller
@RequestMapping("/team/allowanceAward")
public class AllowanceAwardController extends BaseController
{
    private String prefix = "team/allowanceAward";

    @Resource
    private IAllowanceAwardService allowanceAwardService;

    @RequiresPermissions("team:allowanceAward:view")
    @GetMapping()
    public String allowanceAward()
    {
        return prefix + "/allowanceAward";
    }

    /**
     * 查询创业津贴奖励配置列表
     */
    @RequiresPermissions("team:allowanceAward:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AllowanceAward allowanceAward)
    {
        startPage();
        List<AllowanceAward> list = allowanceAwardService.selectAllowanceAwardList(allowanceAward);
        return getDataTable(list);
    }

    /**
     * 导出创业津贴奖励配置列表
     */
    @RequiresPermissions("team:allowanceAward:export")
    @Log(title = "创业津贴奖励配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AllowanceAward allowanceAward)
    {
        List<AllowanceAward> list = allowanceAwardService.selectAllowanceAwardList(allowanceAward);
        ExcelUtil<AllowanceAward> util = new ExcelUtil<AllowanceAward>(AllowanceAward.class);
        return util.exportExcel(list, "allowanceAward");
    }

    /**
     * 新增创业津贴奖励配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存创业津贴奖励配置
     */
    @RequiresPermissions("team:allowanceAward:add")
    @Log(title = "创业津贴奖励配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AllowanceAward allowanceAward) throws ParseException {
        return toAjax(allowanceAwardService.insertAllowanceAward(allowanceAward));
    }

    /**
     * 修改创业津贴奖励配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        AllowanceAward allowanceAward = allowanceAwardService.selectAllowanceAwardById(id);
        mmap.put("allowanceAward", allowanceAward);
        return prefix + "/edit";
    }

    /**
     * 修改保存创业津贴奖励配置
     */
    @RequiresPermissions("team:allowanceAward:edit")
    @Log(title = "创业津贴奖励配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AllowanceAward allowanceAward)
    {
        return toAjax(allowanceAwardService.updateAllowanceAward(allowanceAward));
    }

    /**
     * 删除创业津贴奖励配置
     */
    @RequiresPermissions("team:allowanceAward:remove")
    @Log(title = "创业津贴奖励配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(allowanceAwardService.deleteAllowanceAwardByIds(ids));
    }
}
